package com.gagakuai.engine.impl.event;

import com.gagakuai.engine.delegate.event.*;

/**
 * @program: common-starters
 * @description: 事件分发器实现类
 * @author: houhong
 * @create: 2023-01-02 21:21
 **/
public class ActivitiEventDispatcherImpl implements ActivitiEventDispatcher {

    protected ActivitiEventSupport eventSupport;
    protected boolean enabled = true;

    public ActivitiEventDispatcherImpl() {
        eventSupport = new ActivitiEventSupport();
    }


    @Override
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @Override
    public void addEventListener(ActivitiEventListener listenerToAdd) {
        eventSupport.addEventListener(listenerToAdd);
    }

    @Override
    public void addEventListener(ActivitiEventListener listenerToAdd, ActivitiEventType... types) {
        eventSupport.addEventListener(listenerToAdd, types);
    }

    @Override
    public void removeEventListener(ActivitiEventListener listenerToRemove) {
        eventSupport.removeEventListener(listenerToRemove);
    }


    @Override
    public void dispatchEvent(AbstractActivitiEvent event) {

        if(enabled){
            eventSupport.dispatchEvent(event);
        }

    }
}